/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.reportaccessstorage.service
 * FILE    NAME: ReportAccessStorageDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.reportaccessstorage.service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSON;
import com.hero.common.web.excel.util.ExcelExport;
import com.hero.core.constant.SysConstant;
import com.hero.core.constant.SysDicConstant;
import com.hero.core.entity.PageResult;
import com.hero.core.entity.ResponseEntity;
import com.hero.core.exception.AbstractGenericException;
import com.hero.core.util.DateUtils;
import com.hero.core.util.StringUtils;
import com.hero.core.util.ValidationUtil;
import com.jodinfo.outmirror.api.dictionary.util.DictionaryUtil;
import com.jodinfo.outmirror.api.inventorystkflow.entity.InventoryStkFlowEntity;
import com.jodinfo.outmirror.api.inventorystkflow.service.InventoryStkFlowQueryService;
import com.jodinfo.outmirror.api.org.entity.OrgEntity;
import com.jodinfo.outmirror.api.org.service.OrgQueryService;
import com.jodinfo.outmirror.api.reportaccessstorage.entity.ReportAccessStorageEntity;
import com.jodinfo.outmirror.api.reportaccessstoragebarcode.entity.ReportAccessStorageBarcodeEntity;
import com.jodinfo.outmirror.api.reportaccessstoragebarcode.service.ReportAccessStorageTransactionService;
import com.jodinfo.outmirror.api.reportinventoryanalyze.service.OfficeEntity;
import com.jodinfo.outmirror.api.user.entity.UserEntity;
import com.jodinfo.outmirror.api.user.service.UserQueryService;
import com.jodinfo.outmirror.api.workflow.service.ActivitiTaskQueryService;
import com.taobao.ad.easyschedule.dataobject.JobData;
import com.taobao.ad.easyschedule.dataobject.JobResult;

@Service(value="reportAccessStorageBizService")
public class ReportAccessStorageBizServiceImpl implements ReportAccessStorageBizService {
    private static final Logger logger = LoggerFactory.getLogger(ReportAccessStorageBizServiceImpl.class);
 	
 	@Resource(name="reportAccessStorageDmlService")
	private ReportAccessStorageDmlService ReportAccessStorageDmlService;
	@Resource(name="reportAccessStorageQueryService")
	private ReportAccessStorageQueryService ReportAccessStorageQueryService;
	@Resource(name="reportAccessStorageTransactionService")
	private ReportAccessStorageTransactionService reportAccessStorageTransactionService;
	@Resource(name="activitiTaskQueryService")
	private ActivitiTaskQueryService activitiTaskQueryService;
	@Resource(name="inventoryStkFlowQueryService")
	private InventoryStkFlowQueryService inventoryStkFlowQueryService;
	@Resource(name="orgQueryService")
	private OrgQueryService orgQueryService;
	@Resource(name="userQueryService")
	private UserQueryService userQueryService;
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageBizService#addReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param ReportAccessStorageEntity ReportAccessStorageEntity
	 * @return int
	 */
	public ResponseEntity addReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity) {
			ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
			  	 int i =  ReportAccessStorageDmlService.addReportAccessStorage(ReportAccessStorageEntity);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageBizService#updateReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param ReportAccessStorageEntity ReportAccessStorageEntity
	 * @return ResponseEntity
	 */
	public ResponseEntity updateReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
				int i = ReportAccessStorageDmlService.updateReportAccessStorage(ReportAccessStorageEntity);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageBizService#queryAllReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param ReportAccessStorageEntity ReportAccessStorageEntity
	 * @return String
	 */
	public String queryAllReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity) {
		return JSON.toJSONString(ReportAccessStorageQueryService.queryAllReportAccessStorage(ReportAccessStorageEntity));
	} 
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageBizService#queryAllReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param ReportAccessStorageEntity ReportAccessStorageEntity
	 * @return PageResult
	 */
	public String queryListForPageReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity) {
		List<ReportAccessStorageEntity> list = ReportAccessStorageQueryService.queryListForPageReportAccessStorage(ReportAccessStorageEntity);
		convertCodeToName(list);
		return new PageResult(list , ReportAccessStorageQueryService.queryCountReportAccessStorage(ReportAccessStorageEntity)).toString();
	} 
	
	/**
	 * 数据字典转换
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午4:03:45
	 * @param list
	 */
	private void convertCodeToName(List<ReportAccessStorageEntity> list){
		for(ReportAccessStorageEntity e: list){
			String name = null;
			name = DictionaryUtil.conversionKeyToValue(SysDicConstant.DIC_PARENT_VAL_59, e.getAccessType());
			if(name == null){
				name = DictionaryUtil.conversionKeyToValue(SysDicConstant.DIC_PARENT_VAL_60, e.getAccessType());
			}
			e.setAccessTypeName(name);
		}
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageQueryService#queryById(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param BigInteger id
	 * @return
	 */
	public ReportAccessStorageEntity queryById(BigInteger id) {
		return ReportAccessStorageQueryService.queryById(id);
	}
	
	public void exportReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity, HttpServletResponse response) {
		List<ReportAccessStorageEntity> exportList = null;
		String ids = ReportAccessStorageEntity.getIds();
		if (ValidationUtil.isNullOrEmptyString(ids)) {
			exportList =ReportAccessStorageQueryService.queryAllReportAccessStorage(ReportAccessStorageEntity);
		} else {
			String[] idArray = ids.split(",");
			List<BigInteger> idList = new ArrayList<BigInteger>();
			for(String id : idArray) {
				idList.add(new BigInteger(id));
			}
			exportList = ReportAccessStorageQueryService.queryByIds(idList);
		}
		// 将字典中的code转换为name
		convertCodeToName(exportList);
		ExcelExport.exportExcel(exportList, "ReportAccessStorageEntityExcel", "ReportAccessStorageEntity信息", response);
	}
	
	/** 
	 * 批量删除 数据处理
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageQueryService#queryById(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param BigInteger id
	 * @return
	 */
	public ResponseEntity batchDelReportAccessStorage(ReportAccessStorageEntity ReportAccessStorageEntity) {
		String ids = ReportAccessStorageEntity.getIds();
		String[] idArray = ids.split(",");
		List<ReportAccessStorageEntity> ReportAccessStorageEntityList = new ArrayList<ReportAccessStorageEntity>();
		for(String id : idArray) {
			ReportAccessStorageEntity ReportAccessStorageModel = new ReportAccessStorageEntity();
			ReportAccessStorageModel.setId(new BigInteger(id));
//			ReportAccessStorageModel.setLastUpdateUsrName(UserContext.getUser().getName());
//			ReportAccessStorageModel.setLastUpdateTime(DateUtils.getCurrentTime());
//			ReportAccessStorageModel.setIsDel(SysConstant.IS_DEL_Y);
			ReportAccessStorageModel.setUpdateTime(DateUtils.getCurrentTime());
			ReportAccessStorageEntityList.add(ReportAccessStorageModel);
		}
		return batchUpdateReportAccessStorage(ReportAccessStorageEntityList);
	}
	
	/**
	 * 执行批量删除操作
	 * @author weiwei
	 * @date 2017年3月13日 上午11:40:31
	 * @param ReportAccessStorageList
	 * @return
	 */
	public ResponseEntity batchUpdateReportAccessStorage(List<ReportAccessStorageEntity> ReportAccessStorageList) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
				int i = ReportAccessStorageDmlService.batchUpdateReportAccessStorage(ReportAccessStorageList);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	
	/**
	 * 
	 * @author weiwei
	 * @date 2017年3月13日 上午10:24:53
	 * @see  com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageQueryService#queryById(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param map
	 * @param excelimportcontext
	 * @param s
	 * @return
	 * @throws Exception
	 */
	/*public List<BigInteger> insertData(Map<Integer, List<Object>> map,ExcelImportContext excelimportcontext, String s) throws Exception {
		String usrName = UserContext.getUser().getName();//数据创建人
		String creatTime = DateUtils.getCurrentTime();
		List<ReportAccessStorageEntity> ReportAccessStorageList = validateReportAccessStorageData(map, excelimportcontext,usrName,creatTime);
		if (!excelimportcontext.hasError() && ReportAccessStorageList.size() > 0) {
			batchAddReportAccessStorage(ReportAccessStorageList);
		}
		return null;
	}*/
	
	/**
	 * 
	 * TODO 验证数据 处理业务数据
	 * @author weiwei
	 * @date 2017年3月13日 上午9:33:30
	 * @see  com.jodinfo.outmirror.implementation.reportaccessstorage.ReportAccessStorageQueryService#queryById(ReportAccessStorageEntity ReportAccessStorageEntity)
	 * @param ReportAccessStorageList
	 * @return
	 */
	/*public List<ReportAccessStorageEntity> validateReportAccessStorageData(Map<Integer, List<Object>> map,ExcelImportContext excelimportcontext,String usrName,String creatTime) {
		ExcelImportContext.DataError errorMsg = null;
		List<ReportAccessStorageEntity> ReportAccessStorageList = new ArrayList<ReportAccessStorageEntity>();
		for (Map.Entry<Integer, List<Object>> entity : map.entrySet()) {
			List<Object> excelModelList = entity.getValue();
			if (ValidationUtil.isNullOrEmptyCollection(excelModelList)) {
		//		errorMsg = excelimportcontext.new DataError(InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET,
		//				"导入数据为空！",InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET);
		//		excelimportcontext.push(errorMsg);
			}else{
				//TODO 验证对应数据
				for (int i =0;i<excelModelList.size();i++) {
					ReportAccessStorageEntity ReportAccessStorageModel = (ReportAccessStorageEntity) excelModelList.get(i);
	 				if (checkDataByEntityModel(shShopModel, excelimportcontext, i)) {
						break;
					}
					//TODO 实体对象加入对应参数值 
					ReportAccessStorageModel = setEntityData(ReportAccessStorageModel,usrName, creatTime);
					ReportAccessStorageList.add(ReportAccessStorageModel);
				}
			}
		}
		return ReportAccessStorageList;
	}*/
	
	/**
	 * 
	 * 单个导入实体数据校验 有错误返回true
	 * @author weiwei
	 * @date 2017年3月28日 下午3:59:17
	 * @param eqEquipmentModel
	 * @param excelimportcontext
	 * @param i
	 * @return
	 */
	/*public boolean checkDataByEntityModel(ReportAccessStorageEntity ReportAccessStorageModel,ExcelImportContext excelimportcontext,int i) {
		if (checkSingleData(excelimportcontext, ReportAccessStorageModel.getIsDel, i+2,"错误信息") 
			//	|| checkSingleData(excelimportcontext, ReportAccessStorageModel.getEquipmentColor(), i+2, "颜色为空！")
			//	||checkSingleData(excelimportcontext, ReportAccessStorageModel.getEquipmentModel(), i+2, "型号为空！")
				) {
			return true;
		}else{
			return false;
		}
	}*/
	
	/**
	 * 
	 * 设置报错信息
	 * @author weiwei
	 * @date 2017年3月22日 下午5:17:37
	 * @param excelimportcontext
	 * @param rowNumId
	 * @param errorMessage
	 * @param sheetNumId 现在只有一个sheet 就不传值 默认值即可
	 */
	/*public boolean checkSingleData(ExcelImportContext excelimportcontext,String checkVal,int rowNumId,String errorMessage) {
		boolean flag = false;
		ExcelImportContext.DataError errorMsg = null;
		if (ValidationUtil.isNullOrEmptyString(checkVal)) {
			errorMsg = excelimportcontext.new DataError(rowNumId,errorMessage,InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET);
			excelimportcontext.push(errorMsg);
			flag = true;
		}
		return flag;
	}*/
	
	/**
	 * 
	 * 导入单个实体添加统一导入人及导入时间
	 * @author zhuxiaoliu
	 * @date 2017年3月28日 下午4:05:15
	 * @param eqEquipmentModel
	 * @param usrName
	 * @param creatTime
	 * @return
	 */
	/*public ReportAccessStorageEntity setEntityData(ReportAccessStorageEntity ReportAccessStorageModel,String usrName,String creatTime) {
		
		//ReportAccessStorageModel.setEquipmentId(InventoryConstantUtil.EQ_EQUIPMENT_SEQUENCE);
		ReportAccessStorageModel.setCreateTime(creatTime);
		ReportAccessStorageModel.setCreateUsrName(usrName);
		ReportAccessStorageModel.setLastUpdateUsrName(usrName);
		ReportAccessStorageModel.setLastUpdateTime(creatTime);
		ReportAccessStorageModel.setIsDel(SysConstant.IS_DEL_N);
		return ReportAccessStorageModel;
	}*/
	
	
	/**
	 * 
	 * 执行批插入操作
	 * @author weiwei
	 * @date 2017年3月13日 上午11:37:14
	 * @param {moduleName}List
	 * @return
	 */
	public ResponseEntity batchAddReportAccessStorage(List<ReportAccessStorageEntity> ReportAccessStorageList) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
		try{
			int i = ReportAccessStorageDmlService.batchAddReportAccessStorage(ReportAccessStorageList);
			 rs.setMessage(i+"条记录插入操作成功");
		 }catch(AbstractGenericException e){
			logger.error(e.getFullMessage());
			rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
		}catch(Exception e){
			String errorMessage = StringUtils.toString(e);
			logger.error(errorMessage);
			rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
		}
		return rs;
	}
	public JobResult execute(JobData jobData) throws Exception {
		ResponseEntity rs = scanAccessStorage(null);
		JobResult jobResult = JobResult.succcessResult();
		jobResult.setResultMsg(rs.getMessage());
		return jobResult;
	}
	
	/**
	 * 扫描出入库
	 * @author cao.weiwei
	 * @date 2017年6月30日 下午3:52:38
	 * @return
	 */
	private ResponseEntity scanAccessStorage(String date) {
		ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS,"操作成功");
		try{
			
		
		InventoryStkFlowEntity inventoryStkFlowEntity = new InventoryStkFlowEntity();
		String updateTime = null;
		if(StringUtils.isEmpty(date)){
			String yesterDay = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, DateUtils.getDatePlusDay(new Date(), -1));
			inventoryStkFlowEntity.setLastUpdateTimeEnd(DateUtils.getCurrentTime().substring(0,10));
			inventoryStkFlowEntity.setLastUpdateTimeStart(yesterDay);
			inventoryStkFlowEntity.setIsDel(SysConstant.FAIL);
			String todayDate = DateUtils.getCurrentTime().substring(0,10);
			Date yesterD = DateUtils.getDatePlusDay(DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate), -1);
			updateTime =  DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, yesterD);
		}else{
			Date theDate = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, date);
			Date thDateAfter = DateUtils.getDatePlusDay(theDate, 1);
			String theDateStr = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD,theDate);
			String theDateAfterStr = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD,thDateAfter);
			inventoryStkFlowEntity.setLastUpdateTimeEnd(theDateAfterStr);
			inventoryStkFlowEntity.setLastUpdateTimeStart(theDateStr);
			inventoryStkFlowEntity.setIsDel(SysConstant.FAIL);
			updateTime = theDateStr;
		}
	
		// 查询条码
		List<InventoryStkFlowEntity> InventoryStkFlowEntityList = inventoryStkFlowQueryService.queryAllInventoryStkFlow(inventoryStkFlowEntity);
		List<ReportAccessStorageBarcodeEntity> reportAccessStorageBarcodeEntityList = new ArrayList<ReportAccessStorageBarcodeEntity>();
		if(!CollectionUtils.isEmpty(InventoryStkFlowEntityList)){
			for(InventoryStkFlowEntity entity: InventoryStkFlowEntityList){
				ReportAccessStorageBarcodeEntity reportAccessStorageBarcodeEntity = new ReportAccessStorageBarcodeEntity();
				reportAccessStorageBarcodeEntity.setBusinessId(entity.getBusinessNo());
				reportAccessStorageBarcodeEntity.setEquipmentTypeId(entity.getEquipmentType());
				reportAccessStorageBarcodeEntity.setEquipmentTypeName(entity.getEquipmentTypeName());
				reportAccessStorageBarcodeEntity.setEquipmentId(entity.getEquipmentId());
				reportAccessStorageBarcodeEntity.setEquipmentName(entity.getEquipmentName());
				reportAccessStorageBarcodeEntity.setEquipmentBarcode(entity.getEquipmentBarcode());
				reportAccessStorageBarcodeEntity.setUpdateTime(updateTime);
				reportAccessStorageBarcodeEntity.setAccessType(entity.getBusinessType());
				reportAccessStorageBarcodeEntity.setAccessTime(entity.getLastUpdateTime());
				reportAccessStorageBarcodeEntityList.add(reportAccessStorageBarcodeEntity);
			}
		}
		// 查询分组
		List<ReportAccessStorageEntity> reportAccessStorageEntityList = new ArrayList<ReportAccessStorageEntity>();
		List<InventoryStkFlowEntity> InventoryStkFlowEntityList2 = inventoryStkFlowQueryService.queryByGroup(inventoryStkFlowEntity);
		if(!CollectionUtils.isEmpty(InventoryStkFlowEntityList2)){
			for(InventoryStkFlowEntity entity: InventoryStkFlowEntityList2){
				ReportAccessStorageEntity reportAccessStorageEntity = new ReportAccessStorageEntity();
				OfficeEntity orgMap = getBanchOrg(entity.getOrgId());
				reportAccessStorageEntity.setBranchOrgId(orgMap.getBranchOrgId());
				reportAccessStorageEntity.setBranchOrgName(orgMap.getBranchOrgName());
				reportAccessStorageEntity.setOfficeOrgId(orgMap.getOfficeOrgId());
				reportAccessStorageEntity.setOfficeOrgName(orgMap.getOfficeOrgName());
				reportAccessStorageEntity.setBusinessId(entity.getBusinessNo());
				UserEntity userEntity = new UserEntity();
				userEntity.setUserNo(entity.getCreateUsrName());
				userEntity = userQueryService.queryByEntity(userEntity);
				if(userEntity!=null) reportAccessStorageEntity.setCreateUser(userEntity.getName());
				reportAccessStorageEntity.setCreateUserId(entity.getCreateUsrName());
				reportAccessStorageEntity.setEquipmentTypeId(entity.getEquipmentType());
				reportAccessStorageEntity.setEquipmentTypeName(entity.getEquipmentTypeName());
				reportAccessStorageEntity.setEquipmentId(entity.getEquipmentId());
				reportAccessStorageEntity.setEquipmentName(entity.getEquipmentName());
				reportAccessStorageEntity.setStorageId(entity.getStorageNumId());
				reportAccessStorageEntity.setStorageName(entity.getStorageName());
				reportAccessStorageEntity.setStoragePhyId(entity.getPhysicalStorageId());
				reportAccessStorageEntity.setStoragePhyName(entity.getPhysicalStorageName());
				reportAccessStorageEntity.setUpdateTime(updateTime);
				reportAccessStorageEntity.setAccessType(entity.getBusinessType()); //出入库类型
				reportAccessStorageEntity.setQuantity(entity.getQuantity());
				reportAccessStorageEntity.setAccessTime(entity.getLastUpdateTime()); 
				reportAccessStorageEntityList.add(reportAccessStorageEntity);
			}
		}
		
		reportAccessStorageTransactionService.addReportAccessStorageAndBarcode(reportAccessStorageEntityList,reportAccessStorageBarcodeEntityList);
		}catch(Exception e){
			logger.debug(StringUtils.toString(e));
			rs.setMessage(StringUtils.toString(e));
			rs.setStatus(SysConstant.FAIL);
		}
		return rs;
		
	}
	
	public  OfficeEntity getBanchOrg(String orgId){
		OfficeEntity office = new OfficeEntity();
		 OrgEntity orgEntity = new OrgEntity();
		 List<OrgEntity> orgList =  orgQueryService.queryAllOrg(orgEntity);
		 for(OrgEntity o: orgList){
			 if(o.getOrgId().equals(orgId)){
				 if("0".equals(o.getOrgType())){
					 office.setBranchOrgId(o.getOrgId());
					 office.setBranchOrgName(o.getOrgName());
					 office.setOfficeOrgId(o.getOrgId());
					 office.setOfficeOrgName(o.getOrgName());
				 }else if("1".equals(o.getOrgType())){
					 office.setBranchOrgId(o.getOrgId());
					 office.setBranchOrgName(o.getOrgName());
					 office.setOfficeOrgId(o.getOrgId());
					 office.setOfficeOrgName(o.getOrgName());
				 }else if("2".equals(o.getOrgType())){
					 office.setBranchOrgId(o.getParentOrgId());
					 office.setBranchOrgName(o.getParentOrgName());
					 office.setOfficeOrgId(o.getOrgId());
					 office.setOfficeOrgName(o.getOrgName());
				 }
			 }
		 }
		return office; 
	 }
	public ResponseEntity testTask(String date) {
		if(StringUtils.isEmpty(date)){
			return scanAccessStorage(null);
		}else{
			return scanAccessStorage(date);
		}
		
	}
	
}

